package com.oracle.malldemo.servlet.catalog;

import com.alibaba.fastjson.JSONObject;
import com.oracle.malldemo.domain.Catalog;
import com.oracle.malldemo.view.JsonData;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(value = "/catalog/all")
public class QueryAllCatalogServlet extends CatalogServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/plain;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        List<Catalog> catalogList;
        try {
            catalogList = catalogService.queryAllCatalog();
            JsonData result = JsonData.success("查询类别集合成功！", catalogList);
            out.write(JSONObject.toJSONString(result));
            out.flush();
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            JsonData result = JsonData.fail("程序出现异常！");
            out.write(JSONObject.toJSONString(result));
            //out.write(result.toString());
            out.flush();
            out.close();
        }
    }
}
